home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_threads.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  734 b   |  31 lines

  1. /* Copyrighted Pixar 1989 */
  2. /* From the RenderMan Companion p.367 */
  3. /* Listing 16.24  Displacement shader providing light-bulb threads to cylinder */
  4.  
  5. /*
  6.  * threads(): wrap threads around a cylinder 
  7.  */
  8. displacement 
  9. k3d_threads ( 
  10.     float   Km        =  .1,
  11.         frequency    = 5.0,
  12.         phase        =  .0,
  13.         offset        =  .0,
  14.         dampzone    =  .05 )
  15. {
  16.     float magnitude;
  17.  
  18.     /* Calculate the undamped displacement */
  19.     magnitude = (sin( PI*2*(t*frequency + s + phase))+offset) * Km;
  20.  
  21.     /* Damp the displacement to 0 at each end */
  22.     if( t > (1-dampzone)) 
  23.         magnitude *= (1.0-t) / dampzone;
  24.     else if( t < dampzone )
  25.         magnitude *= t / dampzone;
  26.  
  27.     /* Do the displacement */
  28.     P += normalize(N) * magnitude;
  29.     N = calculatenormal(P);
  30. }
  31.